/*
    Poppi - jQuery plugin - Triggers a popup window
    Copyright (C) 2012  Erik Landvall

    Poppi is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see http://www.gnu.org/licenses/.
 */

( function( $ )
{
    $.fn.poppi = function( options )
    {
        options = $.extend(
            {
                'width':
                    655,
                
                'height':
                    360,
                
                'title':
                    null,
                
                'url':
                    null
            },
            options );
        
        $( this ).click(
            function()
            {
                var title   = null == options.title
                            ? $( this ).attr( 'title' )
                           || $( this ).attr( 'data-title' )
                            : options.title,
                            
                    url     = null == options.url
                            ? $( this ).attr( 'href' )
                           || $( this ).attr( 'data-url' )
                           || $( this ).attr( 'data-href' )
                            : options.url,
                
                    width   = options.width,
                    height  = options.height,
                    
                    left    = ( screen.width  - width )  / 2,
                    top     = ( screen.height - height ) / 2,
					
                    nWindow = window.open(
                        url,
                        title,
                        'toolbar=no,'
                            +'status=no,'
                            +'menubar=no,'
                            +'width='  + width  + ','
                            +'height=' + height + ','
                            +'scrollbars=no,'
                            +'resizable=no,'
                            +'left=' + left + ','
                            +'top='  + top  + ','
                            +'location=no,'
                            +'directories=no,'
                            +'titlebar=no');
                    
                if( window.focus )
                    nWindow.focus();
                
				console.log(url);
				
                return false;
            });
    }
})( jQuery );

jQuery(document).ready(function() {
	jQuery('a.google').poppi();
});